package com.training.schedule_management_system_admin.service;

import com.training.schedule_management_system_admin.entity.*;
import com.training.schedule_management_system_admin.mapper.ScheduleframeworkMapper;
import com.training.schedule_management_system_admin.mapper.ScheduletableMapper;
import com.training.schedule_management_system_admin.mapper.ScheduletermMapper;
import com.training.schedule_management_system_admin.mapper.UserMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ShareService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    ScheduleframeworkMapper scheduleframeworkMapper;

    @Autowired
    ScheduletableMapper scheduletableMapper;

    /*
    获取所有的用户已开放共享的日程框架
     */
    public List<User> getAllFramework() {
        List<User> users=userMapper.getUsernameWithFramework();
        return users;
    }

    /*
    获取所有的用户已公开的日程表
     */
    public List<User> getAllTable(){
        List<User> users = userMapper.getUsernameWithOpenTable();
        return users;
    }

    /*
    日程表模糊查询
     */
    public List<Scheduletable> findOpenTableLike(String value) {
        ScheduletableExample example=new ScheduletableExample();
        ScheduletableExample.Criteria criteria = example.createCriteria();
        criteria.andOpenStateEqualTo(1);
        criteria.andNameLike("%"+value+"%");
        List<Scheduletable> tables = scheduletableMapper.selectByExample(example);
        if(tables!=null && !tables.isEmpty()) {
            return tables;
        }else{
            return Collections.emptyList();
        }
    }

    /*
    日程框架模糊查询
     */
    public List<Scheduleframework> findShareFrameworkLike(String value) {
        ScheduleframeworkExample example=new ScheduleframeworkExample();
        ScheduleframeworkExample.Criteria criteria = example.createCriteria();
        criteria.andShareStateEqualTo(1);
        criteria.andNameLike("%"+value+"%");
        List<Scheduleframework> frameworks =scheduleframeworkMapper.selectByExample(example);
        if(frameworks!=null && !frameworks.isEmpty()) {
            return frameworks;
        }else{
            return Collections.emptyList();
        }
    }
}
